package com.uestc.util;

import java.math.RoundingMode;
import java.text.DecimalFormat;

public class CommonUtil {
	private static DecimalFormat formater = new DecimalFormat();

	/**
	 * double保留小数
	 * 
	 * @param value:待转换的值
	 */
	public static double round(double value) {
		return round(value, 2);
	}

	/**
	 * double保留小数
	 * 
	 * @param value:待转换的值
	 * @param roundNumber:保留roundNumber位小数
	 */
	public static double round(double value, int roundNumber) {
		if (roundNumber < 0) {
			roundNumber = 2;
		}
		formater.setMaximumFractionDigits(roundNumber);
		formater.setRoundingMode(RoundingMode.HALF_UP);
		return Double.valueOf(formater.format(value));
	}
}
